package com.heima.freemarker.controller;

import com.heima.freemarker.pojo.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.*;

@Controller
public class HelloController {

    @GetMapping("/hello")
    public String test(Model model) {
        // 纯文本形式参数
        model.addAttribute("name", "freemarker");
        // 实体类参数
        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        model.addAttribute("stu", student);

        return "01-demo";
    }


    @GetMapping("/list")
    public String list(Model model) {
        // 鸡鸡爆
        Student s1 = new Student();
        s1.setName("鸡鸡爆");
        s1.setAge(18);
        s1.setMoney(1000.86f);
        s1.setBirthday(new Date());

        // 飞飞公主
        Student s2 = new Student();
        s2.setName("飞飞公主");
        s2.setMoney(200.1f);
        s2.setAge(22);

        // 存入list
        List<Student> stus = new ArrayList<>();
        stus.add(s1);
        stus.add(s2);
        model.addAttribute("stus", stus);

        // 创建map数据
        Map<String, Student> stuMap = new HashMap<>();
        stuMap.put("s1", s1);
        stuMap.put("s2", s2);
        model.addAttribute("stuMap", stuMap);
        return "02-list";
    }
}
